package chixing.day11.work.w10;

// 业务流程演示
public class PricingDemo {
    public static void main(String[] args) {
        // 创建产品
        Product book = new Product("Java编程入门", "图书", 99.0, 2);
        Product phone = new Product("智能手机", "电子", 2999.0, 1);
        Product shampoo = new Product("洗发水", "日用品", 50.0, 3);

        // 创建定价上下文
        PricingContext context = new PricingContext();

        // 演示买一赠一策略
        context.setStrategy(new BuyOneGetOneStrategy());
        printResult(book, context);

        // 演示折扣策略
        context.setStrategy(new DiscountStrategy(0.8)); // 八折
        printResult(phone, context);

        // 演示满减策略
        context.setStrategy(new FullReductionStrategy(100, 20)); // 满100减20
        printResult(shampoo, context);
    }

    // 打印计算结果
    private static void printResult(Product product, PricingContext context) {
        double finalPrice = context.calculateFinalPrice(product);
        System.out.println("产品：" + product.getName());
        System.out.println("原价：" + product.getPrice() + " x " + product.getQuantity() + " 件");
        System.out.println("使用策略：" + context.getStrategyName());
        System.out.println("实际价格：" + finalPrice);
        System.out.println("------------------------");
    }
}

